package com.site.user.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import com.site.data.JPABaseDAOImpl;
import com.site.user.pojo.TbRegion;


/**
 * @author      zhanjun
 * @date        2010-12-8
 * @version     1.0
 * @description 角色表服务层
 * 
 */
@Service("tbRegionService")
public class TbRegionService extends JPABaseDAOImpl<TbRegion> implements ITbRegionService {

	
	public List getRegions(String id) {
		if (!StringUtils.hasText(id)) {
			id = "0";
		}
		String jpql="select c.id_Region,c.region_Name,c.region,(select count(t.id_Region) from Tb_Region t where t.pid_region=c.id_Region) as states from Tb_Region c where c.pid_Region='"+id+"'";
		List result=jdbcExecQuery(jpql,null);
	
		List<Map> jsonList = new ArrayList();

		for (int i = 0; i < result.size(); i++) {
			Map mp = new HashMap();
			Object[] objs= (Object[])result.get(i);
			if((null!=objs[0])&&(StringUtils.hasText(objs[0].toString()))){
				mp.put("id", objs[0]);
			}else{
				mp.put("id", "0");
			}
			if((null!=objs[1])&&(StringUtils.hasText(objs[1].toString()))){
				mp.put("text", objs[1]);
			}else{
				mp.put("text", "");
			}
			if((null!=objs[2])&&(StringUtils.hasText(objs[2].toString()))){
				mp.put("attributes", objs[2]);
			}else{
				mp.put("attributes", "");
			}
			if((null!=objs[3])&&(StringUtils.hasText(objs[3].toString()))){
				if(!"0".equals(objs[3].toString()))
				{
				 mp.put("state", "closed");
				}
			}
			jsonList.add(mp);
			
		}
		return jsonList;
	}
}
